
clear
clear all
clear mata
clear matrix
set more off
set matsize 11000
set maxvar 30000
cap log off
capture log close
set emptycells drop
pause on


***********************************************
* USER DEFINE FILEPATH FOR REPLICATION FOLDER *
***********************************************

global path "C:\Users\wb520443\Dropbox\Research Projects\Global pollution\2_analysis\Replication"



***********************************************


global opts		a f plain coll(none) nodep nomti c(b(star fmt(%9.3f)) se(abs par fmt(%9.3f))  ) star(* .10 ** .05 *** .01) noobs nocons

global opts_fs		a f plain coll(none) nodep nomti c(b(star fmt(%9.3f)) se(abs par fmt(%9.3f))) star(* .10 ** .05 *** .01) noobs nocons


global input "$path\data"
global figdat "$path\figdat"
global figures "$path\figures"
global tables "$path\tables"
		
	use "$input/rwi_pollution_analysis_collapsed.dta", replace
	
	
	
	encode country, g(country_code)
	
	g count=1
	
	reg rwi hbase 
		local hbase11=_b[hbase]
		local hbase12=_b[_cons]
		
	reg rwi urban_nl 
		local urban_nl11=_b[urban_nl ]
		local urban_nl12=_b[_cons]
	
	replace rwi=round(rwi,0.01)
	
			
		
	reg rwi urca  if urca<8
		local urca11=_b[urca]
		local urca12=_b[_cons]
		
	reg rwi urca  if urca>7 & urca<15
		local urca21=_b[urca]
		local urca22=_b[_cons]
		
	reg rwi urca if urca>14
		local urca31=_b[urca]
		local urca32=_b[_cons]
		g urca3=urca*_b[urca] + _b[_cons] if urca>14
		
	preserve
		replace rwi = 2 if rwi>2 & rwi!=.
		
		drop count
		rename population count
		
		collapse (sum) count , by(rwi urca)
		
		g urban=1 if urca<8
			replace urban=2 if urca>8 & urca<14
			replace urban=3 if urca>14
			
		
		bysort urban: egen total=total(count)
			replace count=count/total
			
		g urca1=urca*`urca11' + `urca12' if urca<8
		g urca2=urca*`urca21' + `urca22' if urca>7 & urca<15
		g urca3=urca*`urca31' + `urca32' if urca>14
		
		export delimited using "$figdat/urca_rwi.csv", replace
		
		
	restore	
		
		
		
		
	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		